<?php
/**
 * 程序一接口
 * @Description: 去重计算并输出表格
 * @param distnct 去重列
 * @param fields 到处Excel字段列
 * @return \Excel
 */


require './src/Spout/Autoloader/autoload.php';
require './init.php';
require './Sheet.php';

use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
use app\Sheet;


$distinct = $_POST['distnct'];      // XXX: 接口已经定义，该错别字暂不纠正
$outColumns = json_decode($_POST['outColumns'],true);
$secondComputeParams = json_decode($_POST['secondComputeParams'],true);     // 二次计算

// 生成并配置 Excel 写入对象
$writer = WriterFactory::create(Type::XLSX);
$outputFilePath = './download/程序一_'  . date('Y_m_d_H_i_s') . '.xlsx';

$sheetModel = new Sheet;
// 迭代并计算数据，然后写入 Excel
$sheetModel->writerExcel($sheetModel->groupAndOutput($distinct,$outColumns,$writer,$outputFilePath),
    $secondComputeParams);

ajax_success([
	'url'	=>		DOMAIN_NAME . $outputFilePath,
	'code'	=>		'1000'
]);